package com.lp.business.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.iframework.commons.domain.enums.RecordStatus;
import org.iframework.commons.util.fast.V;
import org.iframework.support.spring.hibernate.dao.BaseHibernateDaoSupport;
import org.iframework.support.spring.hibernate.service.BaseServiceSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.lp.business.model.Member;
import com.lp.business.service.CostService;
import com.lp.business.service.LookService;
import com.lp.business.service.MemberService;
import com.lp.business.service.SubscriptionService;

/**
 * 会员服务接口实现类
 * 
 * @author lipeng
 */

@Service("memberService")
public class MemberServiceImpl extends BaseServiceSupport<Member, String> implements MemberService {

	@Autowired
	private SubscriptionService subscriptionService;
	@Autowired
	private CostService costService;
	@Autowired
	private LookService lookService;
	
	@Resource(name = "memberDao")
	@Override
	public void setBaseHibernateDaoSupport(
			@Qualifier("memberDaoImpl") BaseHibernateDaoSupport<Member, String> baseHibernateDaoSupport) {
		this.baseHibernateDaoSupport = baseHibernateDaoSupport;
	}

	@Override
	public Member findMember(Member model) {
		List<Member> list = this.baseHibernateDaoSupport.findByModel(model, null, null);
		return V.isNotEmpty(list)?list.get(0):null;
	}

	@Override
	public Member findByOpenId(String openId) {
		Member model = new Member();
		model.setStatus(RecordStatus.AVAILABLE);
		model.setOpenId(openId);
		List<Member> models = this.findByModel(model, null, null);
		return models != null && models.size() > 0 ? models.get(0) : null;
	}

	@Override
	public boolean isSubscribed(String memberId,String industryId) {
		return subscriptionService.isSubscribed(memberId,industryId);
	}
	
	@Override
	public boolean isPaid(String memberId,String reportId) {
		return costService.isPaid(memberId,reportId);
	}

	@Override
	public Integer freeLookCount(String memberId, String reportId) {
		return lookService.freeLookCount(memberId,reportId);
	}
}
